<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Game
 *
 * @mixin \Eloquent
 */
class Game extends Model
{
    protected $table = 'base_game';
    public $timestamps = false;


    const DEL_NO = 0;
    const DEL_YES = 1;

    static $DelDisplay = [
        self::DEL_NO => '下架',
        self::DEL_YES => '上架',
    ];

    /**
     * 添加游戏
     * @param $request
     * @return array
     */
    static function GamePublish($request)
    {
        $game = new Game();
        foreach ([
                     'name',
                     'sum_energy',
                     'own_frequency',
                     'own_add_energy',
                     'old_friend_frequency',
                     'old_friend_add_energy',
                     'new_friend_frequency',
                     'new_friend_add_energy',
                     'bg_img_url',
                     'cover_img_url',
                     'operating_img_url',
                     'ios_rule_description',
                     'android_rule_description',
                     'floor_img_url',
                     'front_img_url',
                     'operating_name',
                     'click_img_url',
                     'fertilization_cost_coin',
                     'fertilization_keep_days',
                     'fertilization_energy',
                     'fertilization_img_url',
                     'fertilization_click_img_url',
                 ] as $value) {
            $game->$value = $request->$value;
        }
        $game->del_flag = self::DEL_YES;

        if (!$game->save()) {
            return ['status' => 2, 'message' => '添加失败'];
        }

        return ['status' => 1, 'message' => '添加成功'];
    }


    /**
     * 修改游戏
     * @param $game
     * @param $request
     * @return array
     */
    static function GameModify($game, $request)
    {
        foreach ([
                     'name',
                     'sum_energy',
                     'own_frequency',
                     'own_add_energy',
                     'old_friend_frequency',
                     'old_friend_add_energy',
                     'new_friend_frequency',
                     'new_friend_add_energy',
                     'bg_img_url',
                     'cover_img_url',
                     'operating_img_url',
                     'ios_rule_description',
                     'android_rule_description',
                     'floor_img_url',
                     'front_img_url',
                     'operating_name',
                     'click_img_url',
                     'fertilization_cost_coin',
                     'fertilization_keep_days',
                     'fertilization_energy',
                     'fertilization_img_url',
                     'fertilization_click_img_url',
                 ] as $value) {
            $game->$value = $request->$value;
        }

        if (!$game->save()) {
            return ['status' => 2, 'message' => '修改失败'];
        }

        return ['status' => 1, 'message' => '修改成功'];
    }
}
